<?php
    header('Content-Type:text/html;charset=utf-8');
    $ch = curl_init();
    $url = 'http://apis.baidu.com/apistore/weatherservice/cityname?cityname=南宁';
    $header = array(
        'apikey: 11f709693806656bfbd9d8508109e9fa',
    );
    // 添加apikey到header
    curl_setopt($ch, CURLOPT_HTTPHEADER  , $header);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    // 执行HTTP请求
    curl_setopt($ch , CURLOPT_URL , $url);
    $res = curl_exec($ch);

    $q=json_decode($res);
    
    $city=$q->retData->city;
    $d=$q->retData->date;
    $temp=$q->retData->temp;
    echo "$city 在 $d 的气温是 $temp";
    

